<?php

 /**
  * combines all three resizes into one nifty function
  * @param int $id
  * @return bool
  */
 function resize_photos($id)
 {
	 if (small2($id) and medium($id) and large($id))
	 {
	   return true;
	 }
	 else
	 {
		 return false;
	 }
 }


 function small($id)
 {
    // set original image location
		$img = './photos/original/'.$id.'.jpg';

		// set our image canvas
		$canvas_width  = 75;
		$canvas_height = 75;

		// create a blank canvas
		$canvas = imagecreatetruecolor($canvas_width, $canvas_height);

		// get width and height of original image
		list($img_width, $img_height) = getimagesize($img);

		$original = imagecreatefromjpeg($img);

		// copy original onto canvas
		imagecopyresampled($canvas, $original, 0, 0,
			                 (($img_width / 2 ) - ( ($canvas_width / 2) * 4 ) ),
											 (($img_height / 2 ) - ( ($canvas_height / 2) * 4 ) ),
											 $img_width / 4,
											 $img_height / 4,
											 $img_width,
											 $img_height
											 );

		if(imagejpeg($canvas, $_SERVER['DOCUMENT_ROOT'].'/photos/photos/small/'.$id.'.jpg', 80))
		{
		   return true	;
		}
		else
		{
		   return false;
		}

 }


 function small2($id)
 {
    // set original image location
		$img = './photos/original/'.$id.'.jpg';

		// set our image canvas
		$canvas_width  = 75;
		$canvas_height = 75;

		// get width and height of original image
		list($img_width, $img_height) = getimagesize($img);

		$ratio_orig = $img_width / $img_height;

		if($canvas_width / $canvas_height > $ratio_orig)
		{
		  $canvas_width = $canvas_height * $ratio_orig;
		}
		else
		{
			$canvas_height = $canvas_width / $ratio_orig;
		}

		// loading in our original image
		$original = imagecreatefromjpeg($img);

		// create a blank canvas
		$canvas = imagecreatetruecolor($canvas_width, $canvas_height);

     imagecopyresampled($canvas, $original, 0, 0, 0, 0, $canvas_width, $canvas_height, $img_width, $img_height);

		if(imagejpeg($canvas, './photos/small/'.$id.'.jpg', 80))
		{
		   return true	;
		}
		else
		{
		   return false;
		}

 }


function medium($id)
 {
    // set original image location
		$img = './photos/original/'.$id.'.jpg';

		// set our image canvas
		$canvas_width  = 240;
		$canvas_height = 240;

		// get width and height of original image
		list($img_width, $img_height) = getimagesize($img);

		$ratio_orig = $img_width / $img_height;

		if($canvas_width / $canvas_height > $ratio_orig)
		{
		  $canvas_width = $canvas_height * $ratio_orig;
		}
		else
		{
			$canvas_height = $canvas_width / $ratio_orig;
		}

		// loading in our original image
		$original = imagecreatefromjpeg($img);

		// create a blank canvas
		$canvas = imagecreatetruecolor($canvas_width, $canvas_height);

     imagecopyresampled($canvas, $original, 0, 0, 0, 0, $canvas_width, $canvas_height, $img_width, $img_height);

		if(imagejpeg($canvas, './photos/medium/'.$id.'.jpg', 80))
		{
		   return true	;
		}
		else
		{
		   return false;
		}

 }


function large($id)
 {
    // set original image location
		$img = './photos/original/'.$id.'.jpg';

		// set our image canvas
		$canvas_width  = 500;
		$canvas_height = 350;

		// get width and height of original image
		list($img_width, $img_height) = getimagesize($img);

		$ratio_orig = $img_width / $img_height;

		if($canvas_width / $canvas_height > $ratio_orig)
		{
		  $canvas_width = $canvas_height * $ratio_orig;
		}
		else
		{
			$canvas_height = $canvas_width / $ratio_orig;
		}

		// loading in our original image
		$original = imagecreatefromjpeg($img);

		// create a blank canvas
		$canvas = imagecreatetruecolor($canvas_width, $canvas_height);

     imagecopyresampled($canvas, $original, 0, 0, 0, 0, $canvas_width, $canvas_height, $img_width, $img_height);

		if(imagejpeg($canvas, './photos/large/'.$id.'.jpg', 80))
		{
		   return true	;
		}
		else
		{
		   return false;
		}

 }











?>
